{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "DeepSeek: 53.887%\n",
      "豆包: 19.815%\n",
      "Kimi: 10.109%\n",
      "文心一言: 4.621%\n",
      "ChatGPT: 2.260%\n",
      "通义千问: 2.234%\n",
      "智谱清言: 1.903%\n",
      "Gemeni: 1.718%\n",
      "天工AI: 1.314%\n",
      "讯飞星火: 1.295%\n",
      "Claude: 0.459%\n",
      "Copilot: 0.386%\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "\n",
    "#生成一个map数组\n",
    "GlobalApp = {\n",
    "    'ChatGPT': '400.61M',\n",
    "    '豆包': '81.98M',\n",
    "    'DeepSeek':'61.81M',\n",
    "    'Gemeni':'28.4M',\n",
    "    'Kimi':'26.22M',\n",
    "    '文心一言':'12.72M',\n",
    "    '智谱清言':'7.92M',\n",
    "    '讯飞星火':'6.06M',\n",
    "    '天工AI':'5.19M',\n",
    "    '通义千问':'4.76M',\n",
    "    'Claude':'2.95M',\n",
    "}\n",
    "GlobalWeb = {\n",
    "    'ChatGPT': '3.98B',\n",
    "    'Gemeni':'276.15M',\n",
    "    'DeepSeek':'256.54M',\n",
    "    'Claude':'78.29M',\n",
    "    'Copilot':'68.39M',\n",
    "    '豆包':'35.08M',\n",
    "    'Kimi':'33.5M',\n",
    "    '文心一言':'14.58M',\n",
    "    '通义千问':'8.44M',\n",
    "    '智谱清言':'3.32M',\n",
    "    '天工AI':'2.57M',\n",
    "    '讯飞星火':'1.59M',\n",
    "}\n",
    "TotaLTraffic = {\n",
    "    'ChatGPT': '400.61M',\n",
    "    'Gemeni':'304.55M',\n",
    "    'DeepSeek':'318.35M',\n",
    "    'Claude':'81.24M',\n",
    "    'Copilot':'68.39M',\n",
    "    '豆包':'117.06M',\n",
    "    'Kimi':'59.72M',\n",
    "    '文心一言':'27.3M',\n",
    "    '通义千问':'13.2M',\n",
    "    '智谱清言':'11.24M',\n",
    "    '天工AI':'7.76M',\n",
    "    '讯飞星火':'7.65M',\n",
    "}\n",
    "#ChatGPT,Gemeni,Claude,Copilot的访问量均除以30，再重新排序\n",
    "TotaLTraffic = {\n",
    "    'DeepSeek':'318.35M',\n",
    "    '豆包':'117.06M',\n",
    "    'Kimi':'59.72M',\n",
    "    '文心一言':'27.3M',\n",
    "    'ChatGPT':'13.35M',\n",
    "    '通义千问':'13.2M',\n",
    "    '智谱清言':'11.24M',\n",
    "    'Gemeni':'10.15M',\n",
    "    '天工AI':'7.76M',\n",
    "    '讯飞星火':'7.65M',\n",
    "    'Claude':'2.71M',\n",
    "    'Copilot':'2.28M',\n",
    "}\n",
    "# Helper function to convert string with 'M' or 'B' suffix to float\n",
    "def convert_to_float(value):\n",
    "    if value.endswith('M'):\n",
    "        return float(value[:-1]) * 1e6\n",
    "    elif value.endswith('B'):\n",
    "        return float(value[:-1]) * 1e9\n",
    "    else:\n",
    "        return float(value)\n",
    "\n",
    "# 计算每个AI对话助手所占的百分比，并换行输出，保存为Excel，AI对话助手使用排行\n",
    "def calculate_percentage(data):\n",
    "    total_traffic = sum(convert_to_float(traffic) for traffic in data.values())\n",
    "    percentages = {}\n",
    "    for app, traffic in data.items():\n",
    "        percentage = (convert_to_float(traffic) / total_traffic) * 100\n",
    "        percentages[app] = percentage\n",
    "        print(f'{app}: {percentage:.3f}%')\n",
    "    \n",
    "    # Convert to DataFrame\n",
    "    df_percentages = pd.DataFrame(list(percentages.items()), columns=['AI对话助手', '占比'])\n",
    "    \n",
    "    # Save to Excel\n",
    "    df_percentages.to_excel('AI对话助手使用排行.xlsx', index=False)\n",
    "\n",
    "calculate_percentage(TotaLTraffic)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
